Carga de paquetes
library(dplyr)
library(udunits2)
library(sf)
library(DT)
library(plotly)
library(leaflet)
library(rgdal)
library(raster)
Obteniendo datos
primates_cr <-
st_read(
"https://raw.githubusercontent.com/gf0604-procesamientodatosgeograficos/2021i-datos/main/gbif/primates-cr-registros.csv",
options = c(
"X_POSSIBLE_NAMES=decimalLongitude",
"Y_POSSIBLE_NAMES=decimalLatitude"
))
## options: X_POSSIBLE_NAMES=decimalLongitude Y_POSSIBLE_NAMES=decimalLatitude
## Reading layer `primates-cr-registros' from data source
## `https://raw.githubusercontent.com/gf0604-procesamientodatosgeograficos/2021i-datos/main/gbif/primates-cr-registros.csv'
## using driver `CSV'
## Simple feature collection with 4509 features and 50 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -85.96248 ymin: 8.040197 xmax: -82.55949 ymax: 11.15408
## CRS: NA
cantones <-
st_read(
"https://raw.githubusercontent.com/gf0604-procesamientodatosgeograficos/2021i-datos/main/ign/delimitacion-territorial-administrativa/cr_cantones_simp_wgs84.geojson",
quiet = TRUE
)
provincias <-
st_read(
"https://raw.githubusercontent.com/gf0604-procesamientodatosgeograficos/2021i-datos/main/ign/delimitacion-territorial-administrativa/cr_provincias_simp_wgs84.geojson",
)
## Reading layer `cr_provincias_simp_wgs84' from data source
## `https://raw.githubusercontent.com/gf0604-procesamientodatosgeograficos/2021i-datos/main/ign/delimitacion-territorial-administrativa/cr_provincias_simp_wgs84.geojson'
## using driver `GeoJSON'
## Simple feature collection with 7 features and 7 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -87.10189 ymin: 5.498569 xmax: -82.55287 ymax: 11.21964
## Geodetic CRS: WGS 84
st_crs(primates_cr) <- 4326
st_crs(cantones) <- 4326
st_crs(provincias) <- 4326
#Cruce datos
primates_cr <- primates_cr %>%
st_join(cantones["canton"])
Tabla con paquete DT
primates_cr %>%
st_drop_geometry() %>%
dplyr::select(family, species, stateProvince, canton, eventDate) %>%
datatable(colnames = c("Familia", "Especie", "Provincia", "Cantón", "Fecha"),
options = list(searchHighlight = TRUE,
language = list(url = '//cdn.datatables.net/plug-ins/1.10.11/i18n/Spanish.json'),
pageLength = 10))
Gráfico de pastel con Plotly
plot_ly(data = primates_cr, labels = ~species, values = ~4509,
type = "pie") %>%
layout(title= 'Especies') %>%
config(locale = "es")
Mapa de distribución
#Datos altitud raster
alt <- getData(
"worldclim",
var = "alt",
res = .5,
lon = -84,
lat = 10
)
altitud <- crop(alt, extent(-86, -82.3, 8, 11.3))
#Mapa
primates_cr %>%
dplyr::select(stateProvince,
canton,
eventDate) %>%
leaflet() %>%
addProviderTiles(providers$OpenStreetMap.Mapnik, group = "OpenStreetMap") %>%
addProviderTiles(providers$Stamen.TonerLite, group = "Stamen Toner Lite") %>%
addProviderTiles(providers$Esri.WorldImagery, group = "Imágenes de ESRI") %>%
addRasterImage(altitud, col= topo.colors(2), opacity = 0.8,
group = "Altitud") %>%
addCircleMarkers(
stroke = F,
radius = 1,
fillColor = 'red',
fillOpacity = 1,
popup = paste(
primates_cr$stateProvince,
primates_cr$canton,
primates_cr$eventDate,
sep = '<br/>'
),
group = "Primates"
) %>%
addLayersControl(
baseGroups = c("OpenStreetMap", "Stamen Toner Lite", "Imágenes de ESRI",
"Altitud"),
overlayGroups = c("Primates")
) %>%
addMiniMap(
tiles = providers$Stamen.OpenStreetMap.Mapnik,
position = "bottomleft",
toggleDisplay = TRUE
)